﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;

// Token: 0x0200027F RID: 639
public class Map : MonoBehaviour
{
	// Token: 0x06001098 RID: 4248 RVA: 0x0006955C File Offset: 0x0006775C
	private void Awake()
	{
		this.LoadSetup();
		this.reverbs = base.GetComponentsInChildren<AudioReverbZone>();
		for (int i = 0; i < this.reverbs.Length; i++)
		{
			this.reverbs[i].enabled = ConfigData.reverb_flag;
		}
	}

	// Token: 0x06001099 RID: 4249 RVA: 0x000695A8 File Offset: 0x000677A8
	private void Start()
	{
		Skybox skybox = UnityEngine.Object.FindObjectOfType<Skybox>();
		if (skybox != null)
		{
			skybox.material = this.skyMaterial;
		}
		LightMapControl componentInChildren = base.GetComponentInChildren<LightMapControl>();
		if (componentInChildren != null)
		{
			componentInChildren.Apply();
		}
		this.gameCtrl = UnityEngine.Object.FindObjectOfType<GameControl>();
		this.mirrors = base.GetComponentsInChildren<MirrorReflection>();
		if (this.mirrors.Length > 0)
		{
			this.mirrorMaterials = new Material[this.mirrors.Length];
			for (int i = 0; i < this.mirrorMaterials.Length; i++)
			{
				this.mirrorMaterials[i] = this.mirrors[i].GetComponent<Renderer>().material;
			}
		}
		RenderSettings.ambientIntensity = this.ambientIntensity;
		Renderer[] componentsInChildren = base.GetComponentsInChildren<Renderer>();
		for (int j = 0; j < componentsInChildren.Length; j++)
		{
			if (componentsInChildren[j].enabled && componentsInChildren[j].shadowCastingMode != ShadowCastingMode.ShadowsOnly)
			{
				this.renderers.Add(componentsInChildren[j]);
			}
			for (int k = 0; k < this.data.noRecieveShadows.Count; k++)
			{
				if (componentsInChildren[j].name == this.data.noRecieveShadows[k])
				{
					componentsInChildren[j].receiveShadows = false;
					break;
				}
			}
		}
		Terrain[] componentsInChildren2 = base.GetComponentsInChildren<Terrain>();
		for (int l = 0; l < componentsInChildren2.Length; l++)
		{
			this.terrains.Add(componentsInChildren2[l]);
		}
		this.ChangeShow();
	}

	// Token: 0x0600109A RID: 4250 RVA: 0x00069740 File Offset: 0x00067940
	private void Update()
	{
		if (this.mirrors != null)
		{
			for (int i = 0; i < this.mirrors.Length; i++)
			{
				if (this.mirrors[i].enabled != ConfigData.showMirror)
				{
					this.mirrors[i].enabled = ConfigData.showMirror;
					this.mirrors[i].GetComponent<Renderer>().material = ((!ConfigData.showMirror) ? this.gameCtrl.mirrorDummy : this.mirrorMaterials[i]);
				}
			}
		}
		for (int j = 0; j < this.reverbs.Length; j++)
		{
			this.reverbs[j].enabled = ConfigData.reverb_flag;
		}
		this.UpdateShortCutKey();
	}

	// Token: 0x0600109B RID: 4251 RVA: 0x00069800 File Offset: 0x00067A00
	private void UpdateShortCutKey()
	{
		if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject != null)
		{
			return;
		}
		if (Input.GetKeyDown(KeyCode.Alpha3))
		{
			GlobalData.showMap = !GlobalData.showMap;
			this.ChangeShow();
			SystemSE.SE se = (!GlobalData.showMap) ? SystemSE.SE.NO : SystemSE.SE.YES;
			SystemSE.Play(se);
		}
		if (Input.GetKeyDown(KeyCode.Alpha4))
		{
			ConfigData.autoHideObstacle = !ConfigData.autoHideObstacle;
			SystemSE.SE se2 = (!ConfigData.autoHideObstacle) ? SystemSE.SE.NO : SystemSE.SE.YES;
			SystemSE.Play(se2);
			Config config = UnityEngine.Object.FindObjectOfType<Config>();
			if (config)
			{
				config.UpdateFromShortCut();
			}
		}
	}

	// Token: 0x0600109C RID: 4252 RVA: 0x000698B4 File Offset: 0x00067AB4
	private void ChangeShow()
	{
		for (int i = 0; i < this.renderers.Count; i++)
		{
			this.renderers[i].enabled = GlobalData.showMap;
		}
		for (int j = 0; j < this.terrains.Count; j++)
		{
			this.terrains[j].enabled = GlobalData.showMap;
		}
	}

	// Token: 0x0600109D RID: 4253 RVA: 0x00069928 File Offset: 0x00067B28
	private void LoadSetup()
	{
		TagText tagText = new TagText();
		tagText.Load_TextAsset(this.dataText);
		for (int i = 0; i < tagText.ElementNum; i++)
		{
			if (tagText.Elements[i].Tag == "Map")
			{
				tagText.Elements[i].GetVal(ref this.data.name, "name", 0);
				tagText.Elements[i].GetVal(ref this.data.order, "order", 0);
				string empty = string.Empty;
				tagText.Elements[i].GetVal(ref empty, "foot", 0);
				if (empty.Equals("BARE", StringComparison.OrdinalIgnoreCase))
				{
					this.data.foot = MapData.FOOT.BARE;
				}
				else if (empty.Equals("SOCKS", StringComparison.OrdinalIgnoreCase))
				{
					this.data.foot = MapData.FOOT.SOCKS;
				}
				else if (empty.Equals("SHOES", StringComparison.OrdinalIgnoreCase))
				{
					this.data.foot = MapData.FOOT.SHOES;
				}
				tagText.Elements[i].GetVal(ref this.data.selectPos.x, "selectPos", 0);
				tagText.Elements[i].GetVal(ref this.data.selectPos.y, "selectPos", 1);
				tagText.Elements[i].GetVal(ref this.data.selectPos.z, "selectPos", 2);
				tagText.Elements[i].GetVal(ref this.data.selectYaw, "selectYaw", 0);
				tagText.Elements[i].GetVal(ref this.data.mob, "mob", 0);
			}
			else if (tagText.Elements[i].Tag == "H_Pos")
			{
				string empty2 = string.Empty;
				Vector3 zero = Vector3.zero;
				float yaw = 0f;
				tagText.Elements[i].GetVal(ref empty2, "type", 0);
				tagText.Elements[i].GetVal(ref yaw, "yaw", 0);
				TagTextUtility.Load_Vector3(ref zero, tagText.Elements[i], "pos", 0);
				H_Pos h_Pos = new H_Pos(zero, yaw);
				if (empty2.Equals("floor", StringComparison.OrdinalIgnoreCase))
				{
					this.data.h_pos.floor.Add(h_Pos);
				}
				else if (empty2.Equals("chair", StringComparison.OrdinalIgnoreCase))
				{
					this.data.h_pos.chair.Add(h_Pos);
				}
				else if (empty2.Equals("wall", StringComparison.OrdinalIgnoreCase))
				{
					this.data.h_pos.wall.Add(h_Pos);
				}
				else if (empty2.Equals("special", StringComparison.OrdinalIgnoreCase))
				{
					this.data.h_pos.special.Add(h_Pos);
				}
				else if (empty2.Equals("5P_Resist", StringComparison.OrdinalIgnoreCase))
				{
					this.data.h_pos.five_Resist.Add(h_Pos);
				}
				else if (empty2.Equals("5P_Flop", StringComparison.OrdinalIgnoreCase))
				{
					this.data.h_pos.five_Flop.Add(h_Pos);
				}
				else if (empty2.Equals("5P_Weakness", StringComparison.OrdinalIgnoreCase))
				{
					this.data.h_pos.five_Weakness.Add(h_Pos);
				}
				TagText.Attribute attribute = tagText.Elements[i].GetAttribute("watchType");
				if (attribute != null)
				{
					for (int j = 0; j < attribute.vals.Count; j++)
					{
						string empty3 = string.Empty;
						tagText.Elements[i].GetVal(ref empty3, "watchType", j);
						Vector3 zero2 = Vector3.zero;
						TagTextUtility.Load_Vector3(ref zero2, tagText.Elements[i], "watchPos", j * 3);
						float yaw2 = 0f;
						tagText.Elements[i].GetVal(ref yaw2, "watchYaw", j);
						h_Pos.AddWathPos(empty3, zero2, yaw2);
					}
				}
			}
			else if (tagText.Elements[i].Tag == "NoReceiveShadow")
			{
				TagText.Attribute attribute2 = tagText.Elements[i].GetAttribute("renderer");
				if (attribute2 != null)
				{
					for (int k = 0; k < attribute2.vals.Count; k++)
					{
						this.data.noRecieveShadows.Add(attribute2.vals[k]);
					}
				}
			}
		}
	}

	// Token: 0x040011C1 RID: 4545
	[SerializeField]
	private TextAsset dataText;

	// Token: 0x040011C2 RID: 4546
	public Transform lightRoot;

	// Token: 0x040011C3 RID: 4547
	public Material skyMaterial;

	// Token: 0x040011C4 RID: 4548
	public float ambientIntensity = 1f;

	// Token: 0x040011C5 RID: 4549
	public MapData data = new MapData();

	// Token: 0x040011C6 RID: 4550
	private MirrorReflection[] mirrors;

	// Token: 0x040011C7 RID: 4551
	private Material[] mirrorMaterials;

	// Token: 0x040011C8 RID: 4552
	private GameControl gameCtrl;

	// Token: 0x040011C9 RID: 4553
	private List<Terrain> terrains = new List<Terrain>();

	// Token: 0x040011CA RID: 4554
	private List<Renderer> renderers = new List<Renderer>();

	// Token: 0x040011CB RID: 4555
	private bool show = true;

	// Token: 0x040011CC RID: 4556
	private AudioReverbZone[] reverbs;
}
